package com.inmobi.re.controller;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.DownloadManager;
import android.app.DownloadManager.Query;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Binder;
import android.os.Build.VERSION;
import android.os.Vibrator;
import android.provider.MediaStore.Images.Media;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.webkit.JavascriptInterface;
import android.webkit.URLUtil;
import android.widget.FrameLayout;
import com.inmobi.androidsdk.IMBrowserActivity;
import com.inmobi.commons.internal.Log;
import com.inmobi.re.container.IMWebView;
import com.inmobi.re.container.IMWebView.IMWebViewListener;
import com.inmobi.re.container.mraidimpl.AudioTriggerCallback;
import com.inmobi.re.container.mraidimpl.AudioTriggerer;
import com.inmobi.re.controller.util.ImageProcessing;
import com.inmobi.re.controller.util.StartActivityForResultCallback;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicBoolean;
import org.json.JSONException;
import org.json.JSONObject;

public class JSUtilityController extends JSController
{
  DownloadManager a = null;
  Object b;
  private JSDisplayController c;
  private Map<String, Boolean> d = new HashMap();
  private AudioTriggerCallback e = new c(this);
  private boolean f = false;
  private boolean g = false;

  public JSUtilityController(IMWebView paramIMWebView, Context paramContext)
  {
    super(paramIMWebView, paramContext);
    this.c = new JSDisplayController(paramIMWebView, paramContext);
    paramIMWebView.addJavascriptInterface(this.c, "displayController");
  }

  private int a(String paramString, int paramInt)
  {
    try
    {
      int i = Integer.parseInt(paramString);
      return i;
    }
    catch (NumberFormatException localNumberFormatException)
    {
    }
    return paramInt;
  }

  private String a(String paramString)
  {
    if (TextUtils.isEmpty(paramString))
      paramString = null;
    while (paramString.startsWith("tel:"))
      return paramString;
    StringBuilder localStringBuilder = new StringBuilder("tel:");
    localStringBuilder.append(paramString);
    return localStringBuilder.toString();
  }

  private int[] a()
  {
    int[] arrayOfInt = new int[2];
    try
    {
      FrameLayout localFrameLayout = (FrameLayout)((ViewGroup)this.imWebView.getOriginalParent()).getRootView().findViewById(16908290);
      arrayOfInt[0] = ((int)(localFrameLayout.getWidth() / this.imWebView.getDensity()));
      arrayOfInt[1] = ((int)(localFrameLayout.getHeight() / this.imWebView.getDensity()));
      return arrayOfInt;
    }
    catch (Exception localException)
    {
      arrayOfInt[1] = 0;
      arrayOfInt[0] = 0;
    }
    return arrayOfInt;
  }

  private void b()
  {
    if (this.g)
      registerMicListener();
  }

  private void b(final String paramString)
  {
    new f(paramString).start();
  }

  private void c()
  {
    this.g = this.f;
    unRegisterMicListener();
  }

  @SuppressLint({"NewApi"})
  private boolean c(String paramString)
  {
    boolean bool1 = true;
    Boolean localBoolean1 = (Boolean)this.d.get(paramString);
    boolean bool3;
    if (localBoolean1 != null)
    {
      bool3 = localBoolean1.booleanValue();
      return bool3;
    }
    PackageManager localPackageManager = this.imWebView.getActivity().getPackageManager();
    if (paramString.equals("tel"))
    {
      if (localPackageManager.checkPermission("android.permission.CALL_PHONE", localPackageManager.getNameForUid(Binder.getCallingUid())) == 0);
      for (boolean bool5 = bool1; ; bool5 = false)
      {
        Boolean localBoolean12 = Boolean.valueOf(bool5);
        this.d.put(paramString, localBoolean12);
        return localBoolean12.booleanValue();
      }
    }
    if (paramString.equals("sms"))
    {
      Intent localIntent1 = new Intent("android.intent.action.VIEW");
      localIntent1.setType("vnd.android-dir/mms-sms");
      if (this.imWebView.getActivity().getPackageManager().resolveActivity(localIntent1, 65536) == null);
      for (Boolean localBoolean2 = Boolean.valueOf(false); ; localBoolean2 = Boolean.valueOf(bool1))
      {
        this.d.put(paramString, localBoolean2);
        return localBoolean2.booleanValue();
      }
    }
    if (paramString.equals("calendar"))
    {
      Intent localIntent2 = new Intent("android.intent.action.VIEW");
      localIntent2.setType("vnd.android.cursor.item/event");
      if (this.imWebView.getActivity().getPackageManager().resolveActivity(localIntent2, 65536) == null);
      for (Boolean localBoolean3 = Boolean.valueOf(false); ; localBoolean3 = Boolean.valueOf(bool1))
      {
        this.d.put(paramString, localBoolean3);
        return localBoolean3.booleanValue();
      }
    }
    if (paramString.equals("microphone"))
    {
      if (localPackageManager.checkPermission("android.permission.RECORD_AUDIO", localPackageManager.getNameForUid(Binder.getCallingUid())) == 0);
      while (true)
      {
        Boolean localBoolean11 = Boolean.valueOf(bool1);
        this.d.put(paramString, localBoolean11);
        return localBoolean11.booleanValue();
        bool1 = false;
      }
    }
    if (paramString.equals("storePicture"))
    {
      if ((Build.VERSION.SDK_INT > 8) && (localPackageManager.checkPermission("android.permission.WRITE_EXTERNAL_STORAGE", localPackageManager.getNameForUid(Binder.getCallingUid())) == 0));
      while (true)
      {
        Boolean localBoolean10 = Boolean.valueOf(bool1);
        this.d.put(paramString, localBoolean10);
        return localBoolean10.booleanValue();
        bool1 = false;
      }
    }
    if ((paramString.equals("postToSocial.2")) || (paramString.equals("postToSocial.3")) || (paramString.equals("inlineVideo")))
    {
      Boolean localBoolean4 = Boolean.valueOf(bool1);
      this.d.put(paramString, localBoolean4);
      return localBoolean4.booleanValue();
    }
    if (paramString.equals("takeCameraPicture"))
    {
      Intent localIntent3 = new Intent("android.media.action.IMAGE_CAPTURE");
      if (this.imWebView.getActivity().getPackageManager().resolveActivity(localIntent3, 65536) == null);
      for (Boolean localBoolean5 = Boolean.valueOf(false); ; localBoolean5 = Boolean.valueOf(bool1))
      {
        this.d.put(paramString, localBoolean5);
        return localBoolean5.booleanValue();
      }
    }
    if (paramString.equals("getGalleryImage"))
    {
      Intent localIntent4 = new Intent("android.intent.action.PICK", MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
      if (this.imWebView.getActivity().getPackageManager().resolveActivity(localIntent4, 65536) == null);
      for (Boolean localBoolean6 = Boolean.valueOf(false); ; localBoolean6 = Boolean.valueOf(bool1))
      {
        this.d.put(paramString, localBoolean6);
        return localBoolean6.booleanValue();
      }
    }
    boolean bool4;
    label624: Boolean localBoolean8;
    Vibrator localVibrator;
    Boolean localBoolean9;
    if (paramString.equals("vibrate"))
      if (localPackageManager.checkPermission("android.permission.VIBRATE", localPackageManager.getNameForUid(Binder.getCallingUid())) == 0)
      {
        bool4 = bool1;
        localBoolean8 = Boolean.valueOf(bool4);
        localVibrator = (Vibrator)this.c.imWebView.getActivity().getSystemService("vibrator");
        if (localVibrator != null)
          break label688;
        localBoolean9 = Boolean.valueOf(false);
      }
    while (true)
    {
      this.d.put(paramString, localBoolean9);
      return localBoolean9.booleanValue();
      bool4 = false;
      break label624;
      label688: if (Build.VERSION.SDK_INT >= 11)
      {
        if ((localBoolean8.booleanValue()) && (localVibrator.hasVibrator()));
        while (true)
        {
          localBoolean9 = Boolean.valueOf(bool1);
          break;
          bool1 = false;
        }
        boolean bool2 = paramString.equals("html5video");
        bool3 = false;
        if (!bool2)
          break;
        if (Build.VERSION.SDK_INT >= 11)
          if ((!this.imWebView.isHardwareAccelerated()) || (!this.imWebView.isEnabledHardwareAcceleration()));
        for (Boolean localBoolean7 = Boolean.valueOf(bool1); ; localBoolean7 = Boolean.valueOf(bool1))
        {
          this.d.put(paramString, localBoolean7);
          return localBoolean7.booleanValue();
          bool1 = false;
          break;
        }
      }
      localBoolean9 = localBoolean8;
    }
  }

  @JavascriptInterface
  public void asyncPing(String paramString)
  {
    try
    {
      Log.debug("IMRE_3.7.0", "JSUtilityController-> asyncPing: url: " + paramString);
      if (!URLUtil.isValidUrl(paramString))
      {
        this.imWebView.raiseError("Invalid url", "asyncPing");
        return;
      }
      b(paramString);
      return;
    }
    catch (Exception localException)
    {
    }
  }

  @JavascriptInterface
  public void closeVideo(String paramString)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> closeVideo: id :" + paramString);
    this.imWebView.closeVideo(paramString);
  }

  public GregorianCalendar convertDateString(String paramString)
    throws ParseException
  {
    Date localDate = new SimpleDateFormat("yyyy-MM-dd'T'hh:mmZ", Locale.ENGLISH).parse(paramString);
    GregorianCalendar localGregorianCalendar = new GregorianCalendar();
    localGregorianCalendar.setTime(localDate);
    return (GregorianCalendar)localGregorianCalendar;
  }

  @JavascriptInterface
  public void createCalendarEvent(String paramString1, String paramString2, String paramString3, String paramString4)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> createEvent: date: " + paramString1 + " location: " + paramString3 + " body: " + paramString4);
    if (!c("calendar"))
      Log.internal("IMRE_3.7.0", "createCalendarEvent called even if it is not supported");
    while (true)
    {
      return;
      try
      {
        GregorianCalendar localGregorianCalendar1 = convertDateString(paramString1);
        GregorianCalendar localGregorianCalendar2 = convertDateString(paramString2);
        Intent localIntent = new Intent(this.imWebView.getActivity(), IMBrowserActivity.class);
        localIntent.putExtra("id", IMBrowserActivity.generateId(new a()));
        localIntent.putExtra("action", "createCalendarEvent");
        localIntent.putExtra("description", paramString4);
        localIntent.putExtra("location", paramString3);
        localIntent.putExtra("start", localGregorianCalendar1.getTimeInMillis());
        localIntent.putExtra("end", localGregorianCalendar2.getTimeInMillis());
        this.imWebView.getActivity().startActivity(localIntent);
        if (this.imWebView.mListener != null)
        {
          this.imWebView.mListener.onLeaveApplication();
          return;
        }
      }
      catch (Exception localException)
      {
        Log.debug("IMRE_3.7.0", "exception" + localException.getMessage());
        this.imWebView.raiseError("Date format is incorrect", "createCalendarEvent");
      }
    }
  }

  @JavascriptInterface
  public int getAudioVolume(String paramString)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> getAudioVolume: ");
    return this.imWebView.getAudioVolume(paramString);
  }

  @JavascriptInterface
  public String getCurrentPosition()
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> getCurrentPosition");
    synchronized (this.imWebView.mutexcPos)
    {
      this.imWebView.sendToCPHandler();
      while (true)
      {
        boolean bool = this.imWebView.acqMutexcPos.get();
        if (bool)
          try
          {
            this.imWebView.mutexcPos.wait();
          }
          catch (InterruptedException localInterruptedException)
          {
            Log.debug("IMRE_3.7.0", "mutexcPos failed ", localInterruptedException);
          }
      }
    }
    this.imWebView.acqMutexcPos.set(true);
    return this.imWebView.curPosition.toString();
  }

  @JavascriptInterface
  public String getDefaultPosition()
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> getDefaultPosition");
    synchronized (this.imWebView.mutexdPos)
    {
      this.imWebView.sendToDPHandler();
      while (true)
      {
        boolean bool = this.imWebView.acqMutexdPos.get();
        if (bool)
          try
          {
            this.imWebView.mutexdPos.wait();
          }
          catch (InterruptedException localInterruptedException)
          {
            Log.debug("IMRE_3.7.0", "mutexdPos failed ", localInterruptedException);
          }
      }
    }
    this.imWebView.acqMutexdPos.set(true);
    Log.debug("IMRE_3.7.0", "mutexdPassed" + this.imWebView.defPosition);
    return this.imWebView.defPosition.toString();
  }

  @JavascriptInterface
  public String getGalleryImage()
  {
    if (!c("getGalleryImage"))
      Log.internal("IMRE_3.7.0", "getGalleryImage called even if it is not supported");
    do
    {
      return null;
      Intent localIntent = new Intent(this.imWebView.getActivity(), IMBrowserActivity.class);
      localIntent.putExtra("id", IMBrowserActivity.generateId(new c()));
      localIntent.putExtra("action", "getGalleryImage");
      this.imWebView.getActivity().startActivity(localIntent);
    }
    while (this.imWebView.mListener == null);
    this.imWebView.mListener.onLeaveApplication();
    return null;
  }

  @JavascriptInterface
  public String getMaxSize()
  {
    int[] arrayOfInt = a();
    JSONObject localJSONObject = new JSONObject();
    try
    {
      localJSONObject.put("width", arrayOfInt[0]);
      localJSONObject.put("height", arrayOfInt[1]);
      label35: return localJSONObject.toString();
    }
    catch (JSONException localJSONException)
    {
      break label35;
    }
  }

  @JavascriptInterface
  public double getMicIntensity()
  {
    return this.imWebView.getLastGoodKnownMicValue();
  }

  @JavascriptInterface
  public String getScreenSize()
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> getScreenSize");
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    ((WindowManager)this.mContext.getSystemService("window")).getDefaultDisplay().getMetrics(localDisplayMetrics);
    int i = (int)(localDisplayMetrics.widthPixels / localDisplayMetrics.density);
    int j = (int)(localDisplayMetrics.heightPixels / localDisplayMetrics.density);
    JSONObject localJSONObject = new JSONObject();
    try
    {
      localJSONObject.put("width", i);
      localJSONObject.put("height", j);
      return localJSONObject.toString();
    }
    catch (JSONException localJSONException)
    {
      while (true)
        Log.debug("IMRE_3.7.0", "Failed to get screen size");
    }
  }

  @JavascriptInterface
  public int getVideoVolume(String paramString)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> getVideoVolume: ");
    return this.imWebView.getVideoVolume(paramString);
  }

  @JavascriptInterface
  public void hideVideo(String paramString)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> hideVideo: id :" + paramString);
    this.imWebView.hideVideo(paramString);
  }

  @JavascriptInterface
  public boolean isAudioMuted(String paramString)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> isAudioMuted: ");
    return this.imWebView.isAudioMuted(paramString);
  }

  @JavascriptInterface
  public boolean isVideoMuted(String paramString)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> isVideoMuted: ");
    return this.imWebView.isVideoMuted(paramString);
  }

  @JavascriptInterface
  public void log(String paramString)
  {
    Log.debug("IMRE_3.7.0", "Ad Log Message: " + paramString);
  }

  @JavascriptInterface
  public void makeCall(String paramString)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> makeCall: number: " + paramString);
    String str;
    try
    {
      if (this.mContext.checkCallingOrSelfPermission("android.permission.CALL_PHONE") == -1)
      {
        Log.debug("IMRE_3.7.0", "No permission to make call");
        this.imWebView.raiseError("No Permisson to make call", "makeCall");
        return;
      }
      str = a(paramString);
      if (str == null)
      {
        this.imWebView.raiseError("Bad Phone Number", "makeCall");
        return;
      }
    }
    catch (Exception localException)
    {
      Log.debug("IMRE_3.7.0", "Exception in making call ", localException);
      this.imWebView.raiseError("Exception in making call", "makeCall");
      return;
    }
    Intent localIntent = new Intent("android.intent.action.CALL", Uri.parse(str.toString()));
    localIntent.addFlags(268435456);
    this.imWebView.getActivity().startActivity(localIntent);
    this.imWebView.fireOnLeaveApplication();
  }

  @JavascriptInterface
  public void muteAudio(String paramString)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> muteAudio: ");
    this.imWebView.muteAudio(paramString);
  }

  @JavascriptInterface
  public void muteVideo(String paramString)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> muteVideo: ");
    this.imWebView.muteVideo(paramString);
  }

  @JavascriptInterface
  public void openExternal(String paramString)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> openExternal: url: " + paramString);
    this.imWebView.openExternal(paramString);
  }

  @JavascriptInterface
  public void pauseAudio(String paramString)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> pauseAudio: id :" + paramString);
    this.imWebView.pauseAudio(paramString);
  }

  @JavascriptInterface
  public void pauseVideo(String paramString)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> pauseVideo: id :" + paramString);
    this.imWebView.pauseVideo(paramString);
  }

  @JavascriptInterface
  public void playAudio(String paramString1, boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3, String paramString2, String paramString3, String paramString4)
  {
    Log.debug("IMRE_3.7.0", "playAudio: url: " + paramString1 + " autoPlay: " + paramBoolean1 + " controls: " + paramBoolean2 + " loop: " + paramBoolean3 + " startStyle: " + paramString2 + " stopStyle: " + paramString3 + " id:" + paramString4);
    this.imWebView.playAudio(paramString1, paramBoolean1, paramBoolean2, paramBoolean3, paramString2, paramString3, paramString4);
  }

  @JavascriptInterface
  public void playVideo(String paramString1, boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3, boolean paramBoolean4, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6, String paramString7, String paramString8)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> playVideo: url: " + paramString1 + " audioMuted: " + paramBoolean1 + " autoPlay: " + paramBoolean2 + " controls: " + paramBoolean3 + " loop: " + paramBoolean4 + " x: " + paramString2 + " y: " + paramString3 + " width: " + paramString4 + " height: " + paramString5 + " startStyle: " + paramString6 + " stopStyle: " + paramString7 + " id:" + paramString8);
    JSController.Dimensions localDimensions = new JSController.Dimensions();
    localDimensions.x = a(paramString2, -99999);
    localDimensions.y = a(paramString3, -99999);
    localDimensions.width = a(paramString4, -99999);
    localDimensions.height = a(paramString5, -99999);
    if ((localDimensions.width == -99999) && (localDimensions.height == -99999))
    {
      int[] arrayOfInt = a();
      localDimensions.x = 0;
      localDimensions.y = 0;
      localDimensions.width = arrayOfInt[0];
      localDimensions.height = arrayOfInt[1];
    }
    this.imWebView.playVideo(paramString1, paramBoolean1, paramBoolean2, paramBoolean3, paramBoolean4, localDimensions, paramString6, paramString7, paramString8);
  }

  @JavascriptInterface
  public void postToSocial(int paramInt, String paramString1, String paramString2, String paramString3)
  {
    if (!c("postToSocial." + paramInt))
    {
      this.imWebView.raiseError("Social type " + paramInt + " is not supported.", "postToSocial");
      return;
    }
    if (paramString1 == null);
    for (String str = ""; ; str = paramString1)
    {
      if (paramString2 == null)
        str = "";
      if (paramString3 == null)
        paramString3 = "";
      Intent localIntent = new Intent(this.imWebView.getActivity(), IMBrowserActivity.class);
      localIntent.putExtra("id", IMBrowserActivity.generateId(new e()));
      localIntent.putExtra("action", "postToSocial");
      localIntent.putExtra("socialType", paramInt);
      localIntent.putExtra("text", str);
      localIntent.putExtra("link", paramString2);
      localIntent.putExtra("image", paramString3);
      this.imWebView.getActivity().startActivity(localIntent);
      if (this.imWebView.mListener == null)
        break;
      this.imWebView.mListener.onLeaveApplication();
      return;
    }
  }

  @SuppressLint({"NewApi"})
  public void registerBroadcastListener()
  {
    b();
    if (this.b != null);
    while (Build.VERSION.SDK_INT <= 8)
      return;
    try
    {
      if (this.a == null)
        this.a = ((DownloadManager)this.imWebView.getActivity().getSystemService("download"));
      this.b = new b();
      this.imWebView.getActivity().registerReceiver((BroadcastReceiver)this.b, new IntentFilter("android.intent.action.DOWNLOAD_COMPLETE"));
      return;
    }
    catch (Exception localException)
    {
      Log.internal("IMRE_3.7.0", "JSUtilityController-> registerBroadcastListener. Unable to register download listener", localException);
    }
  }

  @JavascriptInterface
  public void registerMicListener()
  {
    if (this.f)
      return;
    this.f = true;
    AudioTriggerer.addEventListener(this.e);
  }

  public void reset()
  {
    if (this.c != null)
      this.c.reset();
  }

  @JavascriptInterface
  public void seekAudio(String paramString, int paramInt)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> seekAudio: ");
    this.imWebView.seekAudio(paramString, paramInt);
  }

  @JavascriptInterface
  public void seekVideo(String paramString, int paramInt)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> seekVideo: ");
    this.imWebView.seekVideo(paramString, paramInt);
  }

  @JavascriptInterface
  public void sendMail(String paramString1, String paramString2, String paramString3)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> sendMail: recipient: " + paramString1 + " subject: " + paramString2 + " body: " + paramString3);
    try
    {
      Intent localIntent1 = new Intent("android.intent.action.SEND");
      localIntent1.setType("plain/text");
      localIntent1.putExtra("android.intent.extra.EMAIL", new String[] { paramString1 });
      localIntent1.putExtra("android.intent.extra.SUBJECT", paramString2);
      localIntent1.putExtra("android.intent.extra.TEXT", paramString3);
      localIntent1.addFlags(268435456);
      Intent localIntent2 = Intent.createChooser(localIntent1, "Choose the Email Client.");
      this.imWebView.getActivity().startActivity(localIntent2);
      this.imWebView.fireOnLeaveApplication();
      return;
    }
    catch (Exception localException)
    {
      Log.debug("IMRE_3.7.0", "Exception in sending mail ", localException);
      this.imWebView.raiseError("Exception in sending mail", "sendMail");
    }
  }

  @JavascriptInterface
  public void sendSMS(String paramString1, String paramString2)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> sendSMS: recipient: " + paramString1 + " body: " + paramString2);
    try
    {
      Intent localIntent = new Intent("android.intent.action.VIEW");
      localIntent.putExtra("address", paramString1);
      localIntent.putExtra("sms_body", paramString2);
      localIntent.setType("vnd.android-dir/mms-sms");
      localIntent.addFlags(268435456);
      this.imWebView.getActivity().startActivity(localIntent);
      this.imWebView.fireOnLeaveApplication();
      return;
    }
    catch (Exception localException)
    {
      Log.debug("IMRE_3.7.0", "Exception in sending SMS ", localException);
      this.imWebView.raiseError("Exception in sending SMS", "sendSMS");
    }
  }

  @JavascriptInterface
  public void setAudioVolume(String paramString, int paramInt)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> setAudioVolume: " + paramString + " " + paramInt);
    this.imWebView.setAudioVolume(paramString, paramInt);
  }

  @JavascriptInterface
  public void setVideoVolume(String paramString, int paramInt)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> setVideoVolume: ");
    this.imWebView.setVideoVolume(paramString, paramInt);
  }

  @JavascriptInterface
  public void showAlert(String paramString)
  {
    Log.debug("IMRE_3.7.0", paramString);
  }

  @JavascriptInterface
  public void showVideo(String paramString)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> showVideo: id :" + paramString);
    this.imWebView.showVideo(paramString);
  }

  public void stopAllListeners()
  {
    try
    {
      this.c.stopAllListeners();
      return;
    }
    catch (Exception localException)
    {
    }
  }

  // ERROR //
  @JavascriptInterface
  @SuppressLint({"NewApi"})
  public void storePicture(String paramString)
  {
    // Byte code:
    //   0: ldc_w 286
    //   3: new 81	java/lang/StringBuilder
    //   6: dup
    //   7: invokespecial 287	java/lang/StringBuilder:<init>	()V
    //   10: ldc_w 821
    //   13: invokevirtual 88	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   16: aload_1
    //   17: invokevirtual 88	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   20: invokevirtual 92	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   23: invokestatic 295	com/inmobi/commons/internal/Log:debug	(Ljava/lang/String;Ljava/lang/String;)V
    //   26: aload_1
    //   27: invokestatic 826	com/inmobi/commons/internal/InternalSDKUtil:getFinalRedirectedUrl	(Ljava/lang/String;)Ljava/lang/String;
    //   30: invokestatic 597	android/net/Uri:parse	(Ljava/lang/String;)Landroid/net/Uri;
    //   33: astore_3
    //   34: aload_0
    //   35: ldc 227
    //   37: invokespecial 353	com/inmobi/re/controller/JSUtilityController:c	(Ljava/lang/String;)Z
    //   40: ifeq +36 -> 76
    //   43: new 828	android/app/DownloadManager$Request
    //   46: dup
    //   47: aload_3
    //   48: invokespecial 831	android/app/DownloadManager$Request:<init>	(Landroid/net/Uri;)V
    //   51: astore 4
    //   53: aload 4
    //   55: getstatic 837	android/os/Environment:DIRECTORY_DOWNLOADS	Ljava/lang/String;
    //   58: aload_3
    //   59: invokevirtual 840	android/net/Uri:getLastPathSegment	()Ljava/lang/String;
    //   62: invokevirtual 844	android/app/DownloadManager$Request:setDestinationInExternalPublicDir	(Ljava/lang/String;Ljava/lang/String;)Landroid/app/DownloadManager$Request;
    //   65: pop
    //   66: aload_0
    //   67: getfield 24	com/inmobi/re/controller/JSUtilityController:a	Landroid/app/DownloadManager;
    //   70: aload 4
    //   72: invokevirtual 848	android/app/DownloadManager:enqueue	(Landroid/app/DownloadManager$Request;)J
    //   75: pop2
    //   76: return
    //   77: astore_2
    //   78: aload_0
    //   79: getfield 99	com/inmobi/re/controller/JSUtilityController:imWebView	Lcom/inmobi/re/container/IMWebView;
    //   82: ldc_w 850
    //   85: ldc 227
    //   87: invokevirtual 306	com/inmobi/re/container/IMWebView:raiseError	(Ljava/lang/String;Ljava/lang/String;)V
    //   90: return
    //   91: astore 5
    //   93: aload_0
    //   94: getfield 99	com/inmobi/re/controller/JSUtilityController:imWebView	Lcom/inmobi/re/container/IMWebView;
    //   97: ldc_w 852
    //   100: ldc 227
    //   102: invokevirtual 306	com/inmobi/re/container/IMWebView:raiseError	(Ljava/lang/String;Ljava/lang/String;)V
    //   105: return
    //
    // Exception table:
    //   from	to	target	type
    //   26	34	77	java/lang/Exception
    //   43	76	91	java/lang/Exception
  }

  @JavascriptInterface
  public String supportsFeature(String paramString)
  {
    return String.valueOf(c(paramString));
  }

  @JavascriptInterface
  public String takeCameraPicture()
  {
    if (!c("takeCameraPicture"))
      Log.internal("IMRE_3.7.0", "takeCameraPicture called even if it is not supported");
    do
    {
      return null;
      Intent localIntent = new Intent(this.imWebView.getActivity(), IMBrowserActivity.class);
      ContentValues localContentValues = new ContentValues();
      final Uri localUri = this.mContext.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, localContentValues);
      localIntent.putExtra("id", IMBrowserActivity.generateId(new d(localUri)));
      localIntent.putExtra("URI", localUri);
      localIntent.putExtra("action", "takeCameraPicture");
      this.imWebView.getActivity().startActivity(localIntent);
    }
    while (this.imWebView.mListener == null);
    this.imWebView.mListener.onLeaveApplication();
    return null;
  }

  @JavascriptInterface
  public void unMuteAudio(String paramString)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> unMuteAudio: ");
    this.imWebView.unMuteAudio(paramString);
  }

  @JavascriptInterface
  public void unMuteVideo(String paramString)
  {
    Log.debug("IMRE_3.7.0", "JSUtilityController-> unMuteVideo: ");
    this.imWebView.unMuteVideo(paramString);
  }

  @SuppressLint({"NewApi"})
  public void unRegisterBroadcastListener()
  {
    try
    {
      c();
      if (Build.VERSION.SDK_INT > 8)
      {
        this.imWebView.getActivity().unregisterReceiver((BroadcastReceiver)this.b);
        this.b = null;
      }
      return;
    }
    catch (Exception localException)
    {
      Log.internal("IMRE_3.7.0", "JSUtilityController-> unregisterBroadcastListener. Unable to unregister download listener", localException);
    }
  }

  @JavascriptInterface
  public void unRegisterMicListener()
  {
    if (!this.f)
      return;
    this.f = false;
    AudioTriggerer.removeEventListener(this.e);
  }

  @JavascriptInterface
  public void vibrate()
  {
    if (!this.imWebView.isViewable())
    {
      this.imWebView.raiseError("Creative not visible. Will not vibrate.", "vibrate");
      return;
    }
    if (c("vibrate"))
    {
      ((Vibrator)this.imWebView.getActivity().getSystemService("vibrator")).vibrate(2000L);
      new Timer().schedule(new g(), 2000L);
      return;
    }
    Log.internal("IMRE_3.7.0", "vibrate called even if it is not supported");
  }

  class a
    implements StartActivityForResultCallback
  {
    a()
    {
    }

    public void onActivityResult(int paramInt, Intent paramIntent)
    {
    }
  }

  class b extends BroadcastReceiver
  {
    b()
    {
    }

    public void onReceive(Context paramContext, Intent paramIntent)
    {
      Cursor localCursor;
      int i;
      if ("android.intent.action.DOWNLOAD_COMPLETE".equals(paramIntent.getAction()))
      {
        long l = paramIntent.getLongExtra("extra_download_id", 0L);
        DownloadManager.Query localQuery = new DownloadManager.Query();
        localQuery.setFilterById(new long[] { l });
        localCursor = JSUtilityController.this.a.query(localQuery);
        if (localCursor.moveToFirst())
        {
          i = localCursor.getColumnIndex("status");
          if (16 != localCursor.getInt(i))
            break label106;
          JSUtilityController.this.imWebView.raiseError("download failed", "storePicture");
        }
      }
      label106: 
      while (8 != localCursor.getInt(i))
        return;
    }
  }

  class c
    implements StartActivityForResultCallback
  {
    c()
    {
    }

    public void onActivityResult(int paramInt, Intent paramIntent)
    {
      if (paramInt == -1)
      {
        Bitmap localBitmap = ImageProcessing.getCompressedBitmap(ImageProcessing.convertMediaUriToPath(paramIntent.getData(), JSUtilityController.this.mContext), JSUtilityController.this.mContext);
        int i = localBitmap.getWidth();
        int j = localBitmap.getHeight();
        String str = ImageProcessing.getBase64EncodedImage(localBitmap, JSUtilityController.this.mContext);
        JSUtilityController.this.imWebView.raiseGalleryImageSelectedEvent(str, i, j);
        return;
      }
      JSUtilityController.this.imWebView.raiseError("User did not select a picture", "getGalleryImage");
    }
  }

  class d
    implements StartActivityForResultCallback
  {
    d(Uri arg2)
    {
    }

    public void onActivityResult(int paramInt, Intent paramIntent)
    {
      if (paramInt == -1)
      {
        if (paramIntent == null);
        for (String str1 = ImageProcessing.convertMediaUriToPath(localUri, JSUtilityController.this.mContext); ; str1 = ImageProcessing.convertMediaUriToPath(paramIntent.getData(), JSUtilityController.this.mContext))
        {
          Bitmap localBitmap = ImageProcessing.getCompressedBitmap(str1, JSUtilityController.this.mContext);
          int i = localBitmap.getWidth();
          int j = localBitmap.getHeight();
          String str2 = ImageProcessing.getBase64EncodedImage(localBitmap, JSUtilityController.this.mContext);
          JSUtilityController.this.imWebView.raiseCameraPictureCapturedEvent(str2, i, j);
          return;
        }
      }
      JSUtilityController.this.imWebView.raiseError("User did not take a picture", "takeCameraPicture");
    }
  }

  class e
    implements StartActivityForResultCallback
  {
    e()
    {
    }

    public void onActivityResult(int paramInt, Intent paramIntent)
    {
    }
  }

  class f extends Thread
  {
    f(String arg2)
    {
    }

    // ERROR //
    public void run()
    {
      // Byte code:
      //   0: aconst_null
      //   1: astore_1
      //   2: aload_0
      //   3: getfield 18	com/inmobi/re/controller/JSUtilityController$f:a	Ljava/lang/String;
      //   6: ldc 26
      //   8: ldc 28
      //   10: invokevirtual 34	java/lang/String:replaceAll	(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
      //   13: astore 4
      //   15: ldc 36
      //   17: new 38	java/lang/StringBuilder
      //   20: dup
      //   21: invokespecial 39	java/lang/StringBuilder:<init>	()V
      //   24: ldc 41
      //   26: invokevirtual 45	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
      //   29: aload 4
      //   31: invokevirtual 45	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
      //   34: invokevirtual 49	java/lang/StringBuilder:toString	()Ljava/lang/String;
      //   37: invokestatic 55	com/inmobi/commons/internal/Log:debug	(Ljava/lang/String;Ljava/lang/String;)V
      //   40: new 57	java/net/URL
      //   43: dup
      //   44: aload 4
      //   46: invokespecial 59	java/net/URL:<init>	(Ljava/lang/String;)V
      //   49: invokevirtual 63	java/net/URL:openConnection	()Ljava/net/URLConnection;
      //   52: checkcast 65	java/net/HttpURLConnection
      //   55: astore 5
      //   57: aload 5
      //   59: sipush 20000
      //   62: invokevirtual 69	java/net/HttpURLConnection:setConnectTimeout	(I)V
      //   65: aload 5
      //   67: ldc 71
      //   69: invokevirtual 74	java/net/HttpURLConnection:setRequestMethod	(Ljava/lang/String;)V
      //   72: aload_0
      //   73: getfield 16	com/inmobi/re/controller/JSUtilityController$f:b	Lcom/inmobi/re/controller/JSUtilityController;
      //   76: getfield 78	com/inmobi/re/controller/JSUtilityController:imWebView	Lcom/inmobi/re/container/IMWebView;
      //   79: getfield 83	com/inmobi/re/container/IMWebView:webviewUserAgent	Ljava/lang/String;
      //   82: astore 8
      //   84: aload 8
      //   86: ifnull +12 -> 98
      //   89: aload 5
      //   91: ldc 85
      //   93: aload 8
      //   95: invokevirtual 88	java/net/HttpURLConnection:setRequestProperty	(Ljava/lang/String;Ljava/lang/String;)V
      //   98: ldc 36
      //   100: new 38	java/lang/StringBuilder
      //   103: dup
      //   104: invokespecial 39	java/lang/StringBuilder:<init>	()V
      //   107: ldc 90
      //   109: invokevirtual 45	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
      //   112: aload 5
      //   114: invokevirtual 94	java/net/HttpURLConnection:getResponseCode	()I
      //   117: invokevirtual 97	java/lang/StringBuilder:append	(I)Ljava/lang/StringBuilder;
      //   120: invokevirtual 49	java/lang/StringBuilder:toString	()Ljava/lang/String;
      //   123: invokestatic 55	com/inmobi/commons/internal/Log:debug	(Ljava/lang/String;Ljava/lang/String;)V
      //   126: aload 5
      //   128: ifnull +8 -> 136
      //   131: aload 5
      //   133: invokevirtual 100	java/net/HttpURLConnection:disconnect	()V
      //   136: return
      //   137: astore_3
      //   138: ldc 36
      //   140: ldc 102
      //   142: aload_3
      //   143: invokestatic 105	com/inmobi/commons/internal/Log:debug	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)V
      //   146: aload_1
      //   147: ifnull -11 -> 136
      //   150: aload_1
      //   151: invokevirtual 100	java/net/HttpURLConnection:disconnect	()V
      //   154: return
      //   155: astore_2
      //   156: aload_1
      //   157: ifnull +7 -> 164
      //   160: aload_1
      //   161: invokevirtual 100	java/net/HttpURLConnection:disconnect	()V
      //   164: aload_2
      //   165: athrow
      //   166: astore 7
      //   168: aload 5
      //   170: astore_1
      //   171: aload 7
      //   173: astore_2
      //   174: goto -18 -> 156
      //   177: astore 6
      //   179: aload 5
      //   181: astore_1
      //   182: aload 6
      //   184: astore_3
      //   185: goto -47 -> 138
      //
      // Exception table:
      //   from	to	target	type
      //   2	57	137	java/lang/Exception
      //   2	57	155	finally
      //   138	146	155	finally
      //   57	84	166	finally
      //   89	98	166	finally
      //   98	126	166	finally
      //   57	84	177	java/lang/Exception
      //   89	98	177	java/lang/Exception
      //   98	126	177	java/lang/Exception
    }
  }

  class g extends TimerTask
  {
    g()
    {
    }

    public void run()
    {
      try
      {
        JSUtilityController.this.imWebView.raiseVibrateCompleteEvent();
        return;
      }
      catch (Exception localException)
      {
        Log.internal("IMRE_3.7.0", "Vibrate callback execption", localException);
      }
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.inmobi.re.controller.JSUtilityController
 * JD-Core Version:    0.6.2
 */